export const Base={
    inject:['reload'],
    data(){
        return {
                
                total:0,
                pagesize:5,
                page:1,
                name:'',
                modal1:false,
                id:'',
                parentId:null,
                type:'',
                ddd:'',
                module:'sort',
               formValidate: {
                    text: '',
                    content: '',
                    
                },
                ruleValidate: {
                    text: [
                        { required: true, message: 'The text cannot be empty', trigger: 'blur' }
                    ],
                    content: [
                        { required: true, message: 'Content cannot be empty', trigger: 'blur' }
                    ]
                }
            }
    },
    methods: {
        loadData (item, callback) {  
            console.log(item)
            console.log(callback)
                this.axios({
                     method:'post',
                url:'http://localhost:3000/sort/list',
               data:{type:item.type}
                }).then(data=>{
                    console.log(111111111111111,data.data)
                callback(data.data);
                
                })     
         },
         renderContent (h, { root, node, data }) {
            return h('span', {
                style: {
                    display: 'inline-block',
                    width: '100%'
                }
            }, [
                h('span', [
                   
                    h('span', data.title)
                ]),
                h('span', {
                    style: {
                        display: 'inline-block',
                        float: 'right',
                        marginRight: '32px'
                    }
                }, [
                    h('Button', {
                        props: Object.assign({}, this.buttonProps, {
                            icon: 'md-add'
                        }),
                        style: {
                        },
                        on: {
                            click: () => { this.append(root,node,data) }
                        }
                    }),
                    h('Button', {
                        props: Object.assign({}, this.buttonProps, {
                            icon: 'md-list'
                        }),
                        on: {
                            click: () => { this.edit(root, node, data) }
                        }
                    }),
                    h('Button', {
                        props: Object.assign({}, this.buttonProps, {
                            icon: 'md-remove'
                        }),
                        on: {
                            click: () => { this.remove(root, node, data) }
                        }
                    })
                ])
            ]);
        },
        append (root,node,data) {
            console.log(data.type);
           this.modal1=true;
           this.type=data.type;
           this.parentId=data._id;
           this.expend=false;
           this.ddd=data;
            this.$refs['formValidate'].resetFields();
            
                

        },
        edit(root, node,data){
        this.modal1=true;
        this.axios({
            method:'get',
            url:`http://localhost:3000/${this.module}/data/${data._id}`
        }).then(res=>{
            console.log(res.data)
            this.formValidate=res.data;
            this.id=res.data._id
        })
        },
        remove (root, node, data) {
         
           this.$Modal.confirm({
            title: 'Delete',
            content: '<p>您确定要删除吗</p>',
            onOk: () => {
                 this.axios({
                    method:'delete',
                    url:`http://localhost:3000/${this.module}/data/${data._id}`
                }).then(()=>{
                //    this.$router.replace({
                //      path:'/blank'
                //     })
                this.reload()
                })
            },
            onCancel: () => {
                this.$Message.info('Cancel delete');
            }
        });
        },
        handleSubmit (name) {
            console.log(this.type)
         if (this.id.length!=0) {
            //修改操作
            this.axios({
                url:`http://localhost:3000/${this.module}/data/${this.id}`,
                method:'put',
                data:this.formValidate
            }).then(res=>{
              
                // this.$router.replace({
                //      path:'/blank'
                //     })
                this.reload()

            })
        }else{
            console.log(this.formValidate.text)
            this.formValidate.title=this.formValidate.text;
            this.formValidate.parentId=this.parentId;
            this.formValidate.type=this.type;

            this.axios({
                url:`http://localhost:3000/${this.module}/data`,
                method:'post',
                data:this.formValidate
            }).then(()=>{
              
            // this.$router.replace({
            //     path:'/blank'
            // })
             this.reload()
             this.$forceUpdate()
               
            })
        }
        }
    
}
}